/*
 * 文件名：InitRule.java	 
 * 时     间：下午4:15:54
 * 作     者：Administrator       
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.billRule.init;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cz073586.common.billRules.entitys.entity.park.ParkBaseConditionEntity;
import com.cz073586.common.billRules.entitys.entity.park.ParkWorkdayBaseConditionEntity;
import com.cz073586.common.billRules.entitys.vo.ParkBillingRuleForOneDayVo;
import com.cz073586.tools.util.Tools;
import com.local.model.LocalChargeBytime;
import com.local.model.LocalChargeBytimeCopy;

/**
 * 类描述:这里是类描述
 * 
 * @ClassName: InitRule
 * @author Administrator
 * @date 2015年12月9日 下午4:15:54
 */
public class InitRule
{
	
	public static ParkBillingRuleForOneDayVo parserParkBillRule(
			List<LocalChargeBytime> list)
	{
		ParkBillingRuleForOneDayVo prf = new ParkBillingRuleForOneDayVo();
		//分段收费Map
		Map<String, ParkBaseConditionEntity> sectionRuleMap = new HashMap<String, ParkBaseConditionEntity>();
		//工作日规则
		ParkWorkdayBaseConditionEntity workday=new ParkWorkdayBaseConditionEntity();
		//非工作日规则
		ParkWorkdayBaseConditionEntity unWorkday=new ParkWorkdayBaseConditionEntity();
		
		//计费规则（按天计算--否）
		ParkBillingRuleForOneDayVo ruleModel = new ParkBillingRuleForOneDayVo();
		
		if (!Tools.isEmpty(list) && list.size() > 0)
		{
			for (LocalChargeBytime lcb : list)
			{
				if(lcb.getAttr().equalsIgnoreCase("2")){
					// 不分段计费
					prf.setSubsection(false);
					//计费规则，转换为引擎数据
					ParkBaseConditionEntity noSection=returnParkBaseConditionEntity(lcb);
					prf.setNoSectionRuleInfo(noSection);
					
				}
				//工作日
				if(!Tools.isEmpty(lcb.getType())&&lcb.getType().equalsIgnoreCase("1")){
					
					//分段收费
					if(!Tools.isEmpty(lcb.getSection())&&lcb.getSection().equalsIgnoreCase("1")){
						
						//类型转换
						ParkBaseConditionEntity pb=returnParkBaseConditionEntity(lcb);
						SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
						String aaa=sdf.format(pb.getSectionStartTime())+"-"+sdf.format(pb.getSectionEndtime());
						sectionRuleMap.put(aaa, pb);
						//放入分段收费规则
						workday.setSectionRuleMap(sectionRuleMap);
						//设置开启分段设置
						workday.setSubsection(true);
					}else{
						//无分段规则
						ParkBaseConditionEntity noSectionRuleInfo=returnParkBaseConditionEntity(lcb);
						workday.setNoSectionRuleInfo(noSectionRuleInfo);
					}
					/*//设置工作日最大收费
					workday.setMaxBill(!Tools.isEmpty(lcb.getAccountTime())?true:false);
					workday.setMaxSateyLong(!Tools.isEmpty(lcb.getAccountTime())?Long.parseLong(lcb.getAccountTime())*60:0);
					workday.setMaxSatyePrice(!Tools.isEmpty(lcb.getMaxCharge())?Double.parseDouble(lcb.getMaxCharge()):0);*/
					//设置工作日分段开启
					prf.setOpenWorkDay(true);
					prf.setWorkday(workday);
				}
				
				//非工作日
				if(!Tools.isEmpty(lcb.getType())&&lcb.getType().equalsIgnoreCase("2")){
					if(!Tools.isEmpty(lcb.getSection())&&lcb.getSection().equalsIgnoreCase("1")){
						//类型转换
						ParkBaseConditionEntity pb=returnParkBaseConditionEntity(lcb);
						SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
						String aaa=sdf.format(pb.getSectionStartTime())+"-"+sdf.format(pb.getSectionEndtime());
						sectionRuleMap.put(aaa, pb);
						//放入分段收费规则
						unWorkday.setSectionRuleMap(sectionRuleMap);
						//设置开启分段设置
						unWorkday.setSubsection(true);
					}else{
						//无分段规则
						ParkBaseConditionEntity noSectionRuleInfo=returnParkBaseConditionEntity(lcb);
						unWorkday.setNoSectionRuleInfo(noSectionRuleInfo);
					}
					
					//设置非工作日最大收费
					/*unWorkday.setMaxBill(!Tools.isEmpty(lcb.getAccountTime())?true:false);
					unWorkday.setMaxSateyLong(!Tools.isEmpty(lcb.getAccountTime())?Long.parseLong(lcb.getAccountTime())*60:0);
					unWorkday.setMaxSatyePrice(!Tools.isEmpty(lcb.getMaxCharge())?Double.parseDouble(lcb.getMaxCharge()):0);*/
					prf.setUnWorkday(unWorkday);
				}
				
				//无区分
				if(!Tools.isEmpty(lcb.getType())&&lcb.getType().equalsIgnoreCase("3")){
					//分段规则
					if(!Tools.isEmpty(lcb.getSection())&&lcb.getSection().equalsIgnoreCase("1")){
						prf.setSubsection(true);
						ParkBaseConditionEntity activitRule=returnParkBaseConditionEntity(lcb);
						SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
						String aaa=sdf.format(activitRule.getSectionStartTime())+"-"+sdf.format(activitRule.getSectionEndtime());
						sectionRuleMap.put(aaa, activitRule);
						prf.setSectionRuleMap(sectionRuleMap);
					}else{
					//非分段规则
						ParkBaseConditionEntity noSectionRuleInfo=returnParkBaseConditionEntity(lcb);
						prf.setNoSectionRuleInfo(noSectionRuleInfo);
						ParkBaseConditionEntity activitRule=returnParkBaseConditionEntity(lcb);
						prf.setActivitRule(activitRule);
					}
					/*prf.setMaxBill(!Tools.isEmpty(lcb.getAccountTime())?true:false);
					prf.setMaxSateyLong(!Tools.isEmpty(lcb.getAccountTime())?Long.parseLong(lcb.getAccountTime())*60:0);
					prf.setMaxSatyePrice(!Tools.isEmpty(lcb.getMaxCharge())?Double.parseDouble(lcb.getMaxCharge()):0);*/
				}
				
				if(!Tools.isEmpty(lcb.getAttr2())){
					// 一天最多收十块
					prf.setMaxPrice(true);
					prf.setMaxPrice(Double.parseDouble(lcb.getAttr2()));
					prf.setSpecial(true);
				}
				
				prf.setMaxBill(!Tools.isEmpty(lcb.getAccountTime())?true:false);
				if(!Tools.isEmpty(lcb.getAccountTime())&&lcb.getAccountTime().equalsIgnoreCase("25")){
					prf.setMaxBill(false);
				}
				prf.setMaxSateyLong(!Tools.isEmpty(lcb.getAccountTime())?Long.parseLong(lcb.getAccountTime())*60:0);
				prf.setMaxSatyePrice(!Tools.isEmpty(lcb.getMaxCharge())?Double.parseDouble(lcb.getMaxCharge()):0);
			}
		}
		return prf;
	}
	
	public static ParkBaseConditionEntity returnParkBaseConditionEntity(LocalChargeBytime lcb){
		try
		{
			if(!Tools.isEmpty(lcb)){
				ParkBaseConditionEntity pcd=new ParkBaseConditionEntity();
				pcd.setFreeTime(Long.parseLong(lcb.getFreeTime()));
				pcd.setFreeTimePrice(Double.parseDouble(lcb.getFreeTimeCharge()));
				SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
				pcd.setSectionStartTime(!Tools.isEmpty(lcb.getSectionStartTime())?sdf.parse(lcb.getSectionStartTime()):null);
				pcd.setSectionEndtime(!Tools.isEmpty(lcb.getSectionEndTime())?sdf.parse(lcb.getSectionEndTime()):null);
				pcd.setCycleTime(Long.parseLong(lcb.getSupassTime()));
				pcd.setCyclePrice(Double.parseDouble(lcb.getAccountTimeCharge()));
				pcd.setCouponTime(Long.parseLong(lcb.getBaseTime()));
				pcd.setCouponPrice(Double.parseDouble(lcb.getBaseTimeCharge()));
				return pcd;
			}
		} catch (Exception e)
		{
			// TODO: handle exception
			return null;
		}
		return null;
	}
}
